package Main;

import Obj.BgObj;
import Obj.BulletsObj;
import Obj.GameObj;
import Utils.GameUtils;

import javax.swing.*;
import java.awt.*;
import java.util.List;
import java.util.ArrayList;

public class GamePanel extends JPanel {
    private List<GameObj> objects = new ArrayList<>();
    private BgObj bgobj;

    public GamePanel(GameObj... gameObjects) {
        for (GameObj obj : gameObjects) {
            objects.add(obj);
        }
        setDoubleBuffered(true);
    }
    //添加新子弹的方法
    //通过多态升级为可添加所有对象
    public void addObj(GameObj obj) {
        objects.add(obj);
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);

        if (GameBegin.state == 0) {
            // 绘制初始界面
            g.drawImage(GameUtils.bg, 0, 0, null);
            g.drawImage(GameUtils.heartImage, 270, 350, null);
            g.drawImage(GameUtils.heroImage, 280, 470, null);
            g.drawImage(GameUtils.bossImage, 120, 70, null);
            g.setColor(Color.red);
            g.setFont(new Font("微软雅黑", Font.BOLD, 50));
            g.drawString("点击鼠标开始游戏", 80, 670);
        }

        if (GameBegin.state == 1) {
            //使用集合统一绘制
            for (GameObj obj : objects) {
                obj.paintSelf(g);
            }
        }
    }
}

